<?php
error_reporting(0);

function vnsurl($source)
	{		
			
				// Lay link image cua chapter do nha :---------------------------------------------------------------
					$mangurl=array();
				//$source=stripcslashes($contents);
								
								
					
					$source=preg_replace("/\?imgmax=2000/","",$source);
					preg_match_all('/lstImages.push\(\"(.*)\"/i',$source, $media);
								$str="";
								foreach($media[1] as $url)
								{	
									$s="<img src='".$url."' />";
									$str.=$s;
								}	
								return  $str;
							
			
		
} 
function blogtruyenurl($data){
	

$data = mb_convert_encoding($data, 'HTML-ENTITIES', "UTF-8"); 
$data=preg_replace("/\?imgmax=1600/","",$data);
$dom = new DOMDocument;
$dom->loadHTML($data);
$sxe = simplexml_import_dom($dom);
$j=1;
foreach ($sxe->xpath("//div[@id='noidungchuong']/img[@src]") as $a){
	
	$str.="<img src='".$a['src']."' /><Br />";
}

return $str;
}
function truyenhayurl($data){

$data = mb_convert_encoding($data, 'HTML-ENTITIES', "UTF-8"); 
$dom = new DOMDocument;
$dom->loadHTML($data);
$sxe = simplexml_import_dom($dom);

foreach ($sxe->xpath("//div[@class='content_chap']/div/a/img[@src]") as $a) {
			$str.="<img src='".$a['src']."' /><Br />";
			echo $str;	
}


return $str;



}

function geturl($url){
$ch = curl_init();
$header=array(
  'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',
  'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'Accept-Language: en-us,en;q=0.5',
  'Accept-Encoding: gzip,deflate',
  'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  'Keep-Alive: 115',
  'Connection: keep-alive',
);

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result=curl_exec($ch);
curl_close($ch);

return $result;
}
function geturl2($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
$result=curl_exec($ch);
curl_close($ch);
return $result;
}

$_POST['url']="http://truyenhay24h.com/Doc-truyen/m1385/307/Chuong-91.html";
if(isset($_POST['url'])){
	if(preg_match("/truyenhay24h.com/i",$_POST['url'])){
		$str=geturl2($_POST['url']);
	
		$data=truyenhayurl($str);
		
		exit();
	
	}
	if(preg_match("/blogtruyen.com/i",$_POST['url'])){
		$str=geturl($_POST['url']);
		$data=blogtruyenurl($str);
		echo $data;
	
	}
	
		if(preg_match("/vnsharing.net/i",$_POST['url'])){
		$str=geturl($_POST['url']);
		$data=vnsurl($str);
		echo $data;
	
	}
}

?>



